/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.internal;

import edu.pku.sei.modeler.icons.ModelerUIIcons;
import edu.pku.sei.modeler.model.core.CorePackage;
import edu.pku.sei.modeler.model.core.MetaModel;
import edu.pku.sei.modeler.ui.palette.DiagramPaletteFactory;
import edu.pku.sei.modeler.ui.palette.EntryDescriptor;

/**
 * @author zl
 *
 */
public class MainProjPaletteFactory extends DiagramPaletteFactory {
	private MainProjPaletteFactory(MetaModel model) {
		super(model);
	}
	
	public static MainProjPaletteFactory getDefault(MetaModel model) {
		DiagramPaletteFactory pFactory = model2factory.get(model);
		if(pFactory == null) {
			pFactory = new MainProjPaletteFactory(model);
			// config the factory
			// for diagram "meta"
			String type = "meta";
			EntryDescriptor entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METACLASS__;
			entry.isNode = true;
			entry.label = "MetaClass";
			entry.shortDesc = "Crate a MetaClass";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.CLASS_ENTRY);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METAENUM__;
			entry.isNode = true;
			entry.label = "MetaEnum";
			entry.shortDesc = "Crate a meta-enumaration";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.ENUM);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METARELATIONSHIP__;
			entry.isNode = true;
			entry.label = "MetaRelationship";
			entry.shortDesc = "Crate a meta-relationship";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.RELATION);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METAPACKAGE__;
			entry.isNode = true;
			entry.label = "Package";
			entry.shortDesc = "Crate a Package";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.PACKAGE_ENTRY);
			pFactory.addEntry(entry);
			
			/*
			 * descriptor = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.RELATION);
			CreationToolEntry referenceNodeEntry = new CreationToolEntry("meta relationship",
					"meta relationship",new MetaCreationFactory(true, StructurePackage.__REFERENCENODE__),
					descriptor,descriptor);
			drawer.add(referenceNodeEntry);
			 */
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METACOMMENT__;
			entry.isNode = true;
			entry.label = "MetaComment";
			entry.shortDesc = "Crate a Comment";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.COMMENT_ENTRY);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METAREFERENCE__;
			entry.isNode = false;
			entry.label = "Reference";
			entry.shortDesc = "Crate a Reference";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.ASSOCIATION_ENTRY);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METAGENERALIZATION__;
			entry.isNode = false;
			entry.label = "Generalization";
			entry.shortDesc = "Crate a Generalization";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.GENERALIZATION_ENTRY);
			pFactory.addEntry(entry);
			
			// for diagram "test"
			type = "test";
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METACLASS__;
			entry.isNode = true;
			entry.label = "MetaClass";
			entry.shortDesc = "Crate a MetaClass";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.CLASS_ENTRY);
			pFactory.addEntry(entry);
			
			entry = new EntryDescriptor();
			entry.diagramType = type;
			entry.elementType = CorePackage.__METAGENERALIZATION__;
			entry.isNode = false;
			entry.label = "Generalization";
			entry.shortDesc = "Crate a Generalization";
			entry.iconSmall = ModelerUIIcons.getImageDescriptor(ModelerUIIcons.GENERALIZATION_ENTRY);
			pFactory.addEntry(entry);
			
			model2factory.put(model, pFactory);
		}
		return (MainProjPaletteFactory)pFactory;
	}
}
